﻿<Page x:Class="TimePunch.Metro.Wpf.Controls.Picker.TimePickerFullMode"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Converter="clr-namespace:TimePunch.Metro.Wpf.Converter" xmlns:local="clr-namespace:TimePunch.Metro.Wpf.Controls.WindowedControl" xmlns:AppBar="clr-namespace:TimePunch.Metro.Wpf.Controls.AppBar" xmlns:Resources="clr-namespace:TimePunch.Metro.Wpf.Resources" mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
	Title="TimePickerFullMode">

    <Page.Resources>
        <Converter:EqualsToVisibilityMultiConverter x:Key="multiConverter" />
        <Converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <Converter:NumberToFixedStringConverter x:Key="NumberToFixedStringConverter" />
    </Page.Resources>
    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Header -->
        <TextBlock Grid.Row="0" 
            Text="{Binding FullModeHeader}" 
            Style="{StaticResource WinTextGroupHeaderStyle}" 
            Margin="{StaticResource WinMargin}"/>

        <!-- Content -->
        <Grid ClipToBounds="True"  Grid.Row="1" x:Name="pickerGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <local:WindowedItemsControl x:Name="hourControl"
                                    ItemsSource="{Binding AllHours}"
                                    SelectedItem="{Binding SelectedHour, Mode=TwoWay}"
                                    IsActiveChanged="OnWindowedItemsControlIsActiveChanged">

                <local:WindowedItemsControl.ItemTemplate>
                    <DataTemplate DataType="local:HourInfo">
                        <Border Width="{StaticResource PickerBox}" Height="{StaticResource PickerBox}"
                            BorderThickness="1"
                            BorderBrush="{Binding ElementName=hourControl,
                                                  Path=Foreground}"
                            Margin="6">
                            <Grid>
                                <Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
                                    <Rectangle.Visibility>
                                        <MultiBinding Converter="{StaticResource multiConverter}">
                                            <Binding />
                                            <Binding ElementName="hourControl" Path="SelectedItem" />
                                        </MultiBinding>
                                    </Rectangle.Visibility>
                                </Rectangle>

                                <TextBlock Text="{Binding Hour, Converter={StaticResource NumberToFixedStringConverter}}"
                                       VerticalAlignment="Center"
                                       Style="{StaticResource WinTextExtraLargeStyle}" />

                                <Rectangle Fill="#80FFFFFF">
                                    <Rectangle.Visibility>
                                        <MultiBinding Converter="{StaticResource multiConverter}"
                                                  ConverterParameter="True">
                                            <Binding />
                                            <Binding ElementName="hourControl" Path="SelectedItem" />
                                        </MultiBinding>
                                    </Rectangle.Visibility>
                                </Rectangle>
                            </Grid>

                            <Border.Visibility>
                                <MultiBinding Converter="{StaticResource multiConverter}">
                                    <Binding />
                                    <Binding ElementName="hourControl" Path="SelectedItem" />
                                    <Binding ElementName="hourControl" Path="IsActive" />
                                </MultiBinding>
                            </Border.Visibility>
                        </Border>
                    </DataTemplate>
                </local:WindowedItemsControl.ItemTemplate>

                <local:WindowedItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <local:WrappableStackPanel IsItemsHost="True" />
                    </ItemsPanelTemplate>
                </local:WindowedItemsControl.ItemsPanel>
            </local:WindowedItemsControl>

            <local:WindowedItemsControl x:Name="minuteControl"
                                    ItemsSource="{Binding AllMinutes}"
                                    SelectedItem="{Binding SelectedMinute, Mode=TwoWay}"
                                    IsActiveChanged="OnWindowedItemsControlIsActiveChanged">

                <local:WindowedItemsControl.ItemTemplate>
                    <DataTemplate DataType="local:MinuteInfo">
                        <Border Width="{StaticResource PickerBox}" Height="{StaticResource PickerBox}"
                            BorderThickness="1"
                            BorderBrush="{Binding ElementName=minuteControl,
                                                  Path=Foreground}"
                            Margin="6">
                            <Grid>
                                <Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
                                    <Rectangle.Visibility>
                                        <MultiBinding Converter="{StaticResource multiConverter}">
                                            <Binding />
                                            <Binding ElementName="minuteControl" Path="SelectedItem" />
                                        </MultiBinding>
                                    </Rectangle.Visibility>
                                </Rectangle>

                                <TextBlock Text="{Binding Minute, Converter={StaticResource NumberToFixedStringConverter}}"
                                       VerticalAlignment="Center"
                                       Style="{StaticResource WinTextExtraLargeStyle}" />

                                <Rectangle Fill="#80FFFFFF">
                                    <Rectangle.Visibility>
                                        <MultiBinding Converter="{StaticResource multiConverter}"
                                                  ConverterParameter="True">
                                            <Binding />
                                            <Binding ElementName="minuteControl" Path="SelectedItem" />
                                        </MultiBinding>
                                    </Rectangle.Visibility>
                                </Rectangle>
                            </Grid>

                            <Border.Visibility>
                                <MultiBinding Converter="{StaticResource multiConverter}">
                                    <Binding />
                                    <Binding ElementName="minuteControl" Path="SelectedItem" />
                                    <Binding ElementName="minuteControl" Path="IsActive" />
                                </MultiBinding>
                            </Border.Visibility>

                        </Border>
                    </DataTemplate>
                </local:WindowedItemsControl.ItemTemplate>

                <local:WindowedItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <local:WrappableStackPanel IsItemsHost="True" />
                    </ItemsPanelTemplate>
                </local:WindowedItemsControl.ItemsPanel>
            </local:WindowedItemsControl>

            <local:WindowedItemsControl x:Name="designatorControl"
                                    ItemsSource="{Binding AllDesignators}"
                                    SelectedItem="{Binding SelectedDesignator, Mode=TwoWay}"
                                    Visibility="{Binding IsDesignatorVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                                    IsActiveChanged="OnWindowedItemsControlIsActiveChanged">

                <local:WindowedItemsControl.ItemTemplate>
                    <DataTemplate DataType="local:DesignatorInfo">
                        <Border Width="{StaticResource PickerBox}" Height="{StaticResource PickerBox}"
                            BorderThickness="1"
                            BorderBrush="{Binding ElementName=designatorControl,
                                                  Path=Foreground}"
                            Margin="6">
                            <Grid>
                                <Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
                                    <Rectangle.Visibility>
                                        <MultiBinding Converter="{StaticResource multiConverter}">
                                            <Binding />
                                            <Binding ElementName="designatorControl" Path="SelectedItem" />
                                        </MultiBinding>
                                    </Rectangle.Visibility>
                                </Rectangle>

                                <TextBlock Text="{Binding}"
                                       VerticalAlignment="Center"
                                       Style="{StaticResource WinTextExtraLargeStyle}" />

                                <Rectangle Fill="#80FFFFFF">
                                    <Rectangle.Visibility>
                                        <MultiBinding Converter="{StaticResource multiConverter}"
                                                  ConverterParameter="True">
                                            <Binding />
                                            <Binding ElementName="designatorControl" Path="SelectedItem" />
                                        </MultiBinding>
                                    </Rectangle.Visibility>
                                </Rectangle>
                            </Grid>

                            <Border.Visibility>
                                <MultiBinding Converter="{StaticResource multiConverter}">
                                    <Binding />
                                    <Binding ElementName="designatorControl" Path="SelectedItem" />
                                    <Binding ElementName="designatorControl" Path="IsActive" />
                                </MultiBinding>
                            </Border.Visibility>

                        </Border>
                    </DataTemplate>
                </local:WindowedItemsControl.ItemTemplate>

                <local:WindowedItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel IsItemsHost="True" />
                    </ItemsPanelTemplate>
                </local:WindowedItemsControl.ItemsPanel>
            </local:WindowedItemsControl>
        </Grid>

        <!-- Application Bar -->
        <AppBar:ApplicationBar Grid.Row="2" Background="{StaticResource WinChromeBrush}">
            <AppBar:ApplicationBar.Icons>
                <AppBar:ApplicationBarIcon ImageSource="/TpMetroWpfLibrary;component/Images/appbar.check.png"
                                           Description="{x:Static Resources:CommonResources.Button_Ok}"
                                           Command="{Binding CheckCommand}"/>
                <AppBar:ApplicationBarIcon ImageSource="/TpMetroWpfLibrary;component/Images/appbar.cancel.png"
                                           Description="{x:Static Resources:CommonResources.Button_Cancel}"
                                           Command="{Binding CancelCommand}"/>
            </AppBar:ApplicationBar.Icons>
        </AppBar:ApplicationBar>
    </Grid>
</Page>
